package Thread;

import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by sunyuming on 18/10/23.
 */
public class MySchedule {
    public static void main(String[] args) {
        int corePoolSize = 1;
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(corePoolSize);

        pool.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                System.out.println('a');
            }
        }, 0, 10, TimeUnit.SECONDS);

        pool.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                System.out.println('b');
            }
        }, 0, 10, TimeUnit.SECONDS);

        pool.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                System.out.println('c');
                throw new RuntimeException("test");
            }
        }, 0, 10, TimeUnit.SECONDS);
    }
}
